package com.zbkj.service.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.zbkj.common.constants.AlipayConfig;
import com.zbkj.service.service.SystemConfigService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class ALiPayConfig {

    private static final String GATEWAY_URL = "https://openapi.alipay.com/gateway.do";
    private static final String FORMAT = "JSON";
    private static final String CHARSET = "utf-8";
    private static final String SIGN_TYPE = "RSA2";

    @Resource
    private SystemConfigService systemConfigService;

    @Bean
    public AlipayClient initAlipayClient() {
        return new DefaultAlipayClient(GATEWAY_URL, systemConfigService.getValueByKey(AlipayConfig.APPID),
                systemConfigService.getValueByKey(AlipayConfig.RSA_PRIVATE_KEY), FORMAT, CHARSET,
                systemConfigService.getValueByKey(AlipayConfig.ALIPAY_PUBLIC_KEY_2), SIGN_TYPE);
    }
}
